import numpy as np
import sounddevice as sd
from scipy.signal import resample
from ssqueezepy import issq_stft


def audio_validate(model, data_gen, config):
    prediction = model.predict(np.array([[0.2, 0.3]]))
    channels = []
    print('正在播放预测声音')
    for i in range(prediction.shape[-1]):
        dat = issq_stft(prediction[0, ..., i]).reshape(-1)
        da = resample(dat, config['src_len'])
        channels.append(da)
    sd.play(np.stack(channels, axis=-1), config['source_sample_rate'], blocking=True)
    print('播放结束')


def validate(model, data_gen, config):
    if config['model_type'] == 'audio2audio':
        audio_validate(model, data_gen, config)

